import os
import django
from celery import Celery
from django.conf import settings
from celery.schedules import crontab

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')

app = Celery('application')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django apps.
app.autodiscover_tasks()

# 定时任务调度
# app.conf.beat_schedule = {
#     "every-midnight-check-account-lock": {
#         'task': 'get_has_account_lock',
#         "schedule": crontab(minute='*/2'),
#         'args': ()
#     }
# }


# @app.task(bind=True)
# def debug_task(self):
#     print(f'Request: {self.request!r}')


# from django.conf import settings
# from celery import platforms
# # 租户模式
# if "django_tenants" in settings.INSTALLED_APPS:
#     from tenant_schemas_celery.app import CeleryApp as TenantAwareCeleryApp
#
#     app = TenantAwareCeleryApp()
# else:
#     from celery import Celery
#
#     app = Celery(f"application")
# app.config_from_object('django.conf:settings')
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
# platforms.C_FORCE_ROOT = True
